
package com.wyzz.hr.action;

import java.util.*;
import javax.servlet.ServletRequest;
import org.apache.axis.utils.StringUtils;

import com.wyzz.hr.bo.IEmployeeBo;
import com.wyzz.hr.util.DateUtil;


public class EmployeeSumAction extends EmployeeReportAction {

	public EmployeeSumAction() {
	}

	public String execute() throws Exception {
		String result = super.execute();
		ServletRequest request = getRequest();
		String startDate = request.getParameter("startDate");
		String endDate = request.getParameter("endDate");
		if (!checkDate(startDate, endDate)) {
			return "input";
		} else {
			String groupBy = request.getParameter("groupBy");
			IEmployeeBo empBo = (IEmployeeBo) getBean("empBo");
			java.util.List empSumList = empBo.getEmpSumReport(startDate,
					endDate, groupBy);
			Map params = new HashMap();
			params.put("empSumList", empSumList);
			request.setAttribute("_params", params);
			return result;
		}
	}

	private boolean checkDate(String startDate, String endDate) {
		boolean flag = true;
		String mes = "";
		if (StringUtils.isEmpty(startDate))
			mes = (new StringBuilder()).append(mes).append(
					"\u5F00\u59CB\u65F6\u95F4\u4E3A\u7A7A\uFF01").toString();
		if (StringUtils.isEmpty(startDate))
			mes = (new StringBuilder()).append(mes).append(
					"\u7ED3\u675F\u65F6\u95F4\u4E3A\u7A7A\uFF01").toString();
		if (DateUtil.parseDateByFormat(startDate, "yyyy-MM-dd").compareTo(
				DateUtil.parseDateByFormat(endDate, "yyyy-MM-dd")) > 0)
			mes = (new StringBuilder())
					.append(mes)
					.append(
							"\u5F00\u59CB\u65F6\u95F4\u5927\u4E8E\u7ED3\u675F\u65F6\u95F4\uFF01")
					.toString();
		if (!"".equals(mes)) {
			addActionError(mes);
			flag = false;
		}
		return flag;
	}

	private static final long serialVersionUID = 1L;
}
